<?php
use common\models\Article;
?>
<?php $this->beginBlock('title'); ?>手机网游活动_安卓、IOS网游资讯频道_手机网游下载_二狐游戏<?php $this->endBlock();?>
<?php $this->beginBlock('keywords'); ?>手机网游活动,手机网游下载,手机网游福利<?php $this->endBlock();?>
<?php $this->beginBlock('description'); ?>最新手游活动资讯，最豪华手游活动福利，最新、最热手游下载，二狐游戏下载<?php $this->endBlock();?>
<!--新闻汇总-->
<div class="public womargin">
     <div class="collect_tab">
         <ul class="clearfix">
             <li><p><em>新闻</em></p></li>
             <li class="hover"><span><em>活动</em></span></li>
         </ul>
     </div>
</div>
<div class="collect_list">
    <div class="collect_news_list" style="display:none">
        <ul class="me_shadow" id="article_list1">
            <?php foreach($news as $item):?>
            <li><a href="<?=Yii::$app->urlManager->createUrl(['article/detail','id'=>$item['id']]);?>">
               <p class="p1"><img src="<?=filepath($item['logo_path']);?>"></p>
               <p class="p2">
                  <span class="span1"><?=truncate($item['title'],25);?></span>
                  <span class="span2"><?=date('Y-m-d',$item['created_at']);?></span>
               </p>
            </a></li>
            <?php endforeach;?>
        </ul>
        <div class="loadgame" id="loadgame1" data-page="2"><p>加载更多资讯 </p></div>
    </div>
    <div class="collect_news_list">
        <ul class="me_shadow" id="article_list2">
            <?php foreach($activity as $item):?>
            <li><a href="<?=Yii::$app->urlManager->createUrl(['article/detail','id'=>$item['id']]);?>">
               <p class="p1"><img src="<?=filepath($item['logo_path']);?>"></p>
               <p class="p2">
                  <span class="span1"><?=truncate($item['title'],25);?></span>
                  <span class="span2"><?=date('Y-m-d',$item['created_at']);?></span>
               </p>
            </a></li>
            <?php endforeach;?>
        </ul>
        <div class="loadgame" id="loadgame2" data-page="2"><p>加载更多资讯 </p></div>
    </div>
</div>

<?php $this->beginBlock('script'); ?>
<script type="text/javascript">
//点击加载更多时，瀑布流实现
$("#loadgame1,#loadgame2").click(function() {
	var obj=$(this);
    getArticles(obj);
});

//将时间戳转化为2015-09-09这样格式的日期 by jois add at 20150911
function formatDate(date){
	date=new Date(parseInt(date)*1000).toLocaleDateString();
	return date.replace(/\//g, '-').replace(/-(\d)?/, "-0$1");;
}

//加载更多函数
function getArticles(obj){
	//初始化参数
	var add = obj;
	//抓取tab面板的编号，id最后一个数字
	var tab_num=add.attr("id").substr(-1,1);
	if(tab_num==1){
		var kind="<?=Article::KIND_NEWS;?>";
	}else{
		var kind="<?=Article::KIND_ACTIVITY;?>";
    }
	var page = parseInt(add.attr('data-page'));
	if (isNaN(page) || page < 2) {
        page = 2;
    }

    //防止恶意点击
	if (add.attr('data-action') == 1) {
        return false;
    }
	add.attr('data-action', 1);
    add.find('p').text('获取中...');

    //ajax请求数据
    $.ajax({
        type: 'GET',
        url: "<?=Yii::$app->urlManager->createUrl('/article/ajax-list')?>",
        data: { page: page, kind: kind },
        dataType: 'json',
        success: function(data) {
            if (data.length < 1) {
                add.hide();
            } else {
                var html = "";
                var file_path1="<?=\Yii::$app->params['filePath'];?>";
                var file_path2="<?=\Yii::$app->params['pipawImgPath'];?>";
                var detail_path="<?=Yii::$app->urlManager->createUrl('article/detail');?>";
                for (var i in data) {
                    if(data[i]['logo_path'].substr(0,1)=='/'){
                    	var img_path=file_path1+data[i]['logo_path'];
                    }else{
                    	var img_path=file_path2+data[i]['logo_path'];
                    }
                    html+='<li><a href="'+detail_path+'?id='+data[i]['id']+'"><p class="p1"><img src="'+img_path+'"></p>' +
                	'<p class="p2"><span class="span1">'+data[i]['title']+'</span><span class="span2">'+formatDate(data[i]['created_at'])+'</span></p></a></li>';
                }
                if(tab_num==1){
                	$("#article_list1").append(html);
                }else{
                	$("#article_list2").append(html);
                }
                add.attr('data-page', parseInt(add.attr('data-page'))+1);
            }
            add.attr('data-action', 0);
            add.find('p').text('加载更多资讯');
        },
        error: function(xhq) {
        	alert(xhq.responseText);
            add.attr('data-action', 0);
            add.find('p').text('加载更多资讯');
        }
    });
}
</script>
<?php $this->endBlock();?>